package com.xty.xtyle.db;

import android.text.TextUtils;

import org.litepal.LitePal;

import java.util.List;

public class UserDao {

    public void add(User user) {
        if (null != user) user.save();
    }

    public void update(User user, String newName) {
        if (null == user || TextUtils.isEmpty(newName)) return;
        user.updateAll("name = ?",newName);
    }

    public void delete(String name) {
        if (TextUtils.isEmpty(name)) return;
        LitePal.deleteAll(User.class, "name=?", name);
    }

    public List<User> findAll() {
        return LitePal.findAll(User.class);
    }

    public User findUser(String name) {
        if (TextUtils.isEmpty(name)) return null;
        return LitePal.where("name=?", name).findFirst(User.class);
    }

    public User findFirst() {
        return LitePal.findFirst(User.class);
    }

    public void order() {
//        List<User> books = LitePal.order("price desc").find(Book.class);
    }
}
